package io.scnb.lesson001.demo7;

import org.springframework.beans.factory.DisposableBean;

/**
 * 通过depend-on来干预bean创建和销毁顺序
 * depend-on可以制定当前bean依赖的bean，确保depend-on制定的bean在当前
 * bean创建之前先创建好，销毁顺序刚好相反
 */
public class DependOnBean {

    public static class Bean1 implements DisposableBean {

        public Bean1() {
            System.out.println(this.getClass() + " constructor!");
        }

        @Override
        public void destroy() throws Exception {
            System.out.println(this.getClass() + " destroy");
        }
    }

    public static class Bean2 implements DisposableBean {

        public Bean2() {
            System.out.println(this.getClass() + " constructor!");
        }

        @Override
        public void destroy() throws Exception {
            System.out.println(this.getClass() + " destroy");
        }
    }

    public static class Bean3 implements DisposableBean {

        public Bean3() {
            System.out.println(this.getClass() + " constructor!");
        }

        @Override
        public void destroy() throws Exception {
            System.out.println(this.getClass() + " destroy");
        }
    }
}
